<?php

namespace Psg;

use Application\Config as Config;

import('Application.Config');
import('Swift.Mail');

class Notifier {

    protected $swiftSmtpHandle;
    protected $swiftMsgHandle;

    public function __construct() {
        $this->swiftSmtpHandle = \Swift_SmtpTransport::newInstance(Config::notifierSmtpHost, 465, 'ssl')
                ->setUsername(Config::notifierUsername)
                ->setPassword(Config::notifierPassword);
        return $this;
    }

    public function Send(array $to, $topic, $content) {
        $this->swiftMsgHandle = \Swift_Mailer::newInstance($this->swiftSmtpHandle);
        $message = \Swift_Message::newInstance($topic)
                ->setFrom(['portal.psg@gmail.com' => 'Portal PSG'])
                ->setTo($to)
                ->setBody(\View::factory('_mail')->set('content', $content)->render(), 'text/html');
        $this->swiftMsgHandle->send($message);
    }

}
